package com.autumn.config.api.consts;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * 配置状态常量
 * 
 * @author 老码农
 *         <p>
 *         Description
 *         </p>
 * @date 2017-12-30 20:58:25
 */
public class ConfigureConsts {	

	/**
	 * 状态
	 * 
	 * @author 老码农
	 *         <p>
	 *         Description
	 *         </p>
	 * @date 2017-12-30 20:59:31
	 */
	public static class StatusConsts {
		/**
		 * 草稿状态
		 */
		public static final int STATUS_DRAFT = 1;

		/**
		 * 发布状态
		 */
		public static final int STATUS_RELEASE = 2;

		/**
		 * 停用状态
		 */
		public static final int STATUS_DISABLE = 3;

		/**
		 * 删除状态
		 */
		public static final int STATUS_DELETED = 4;

		private final static Map<Integer, String> NAME_MAP = new HashMap<>();

		static {
			NAME_MAP.put(STATUS_DRAFT, "待发布");
			NAME_MAP.put(STATUS_RELEASE, "已发布");
			NAME_MAP.put(STATUS_DISABLE, "已停用");
			NAME_MAP.put(STATUS_DELETED, "已删除");
		}

		/**
		 * 获取名称
		 * 
		 * @param value
		 *            值
		 * @return
		 */
		public static String getName(Integer value) {
			if (value == null) {
				return null;
			}
			return NAME_MAP.get(value);
		}
	}

	/**
	 * 连接类型
	 * 
	 * @author 老码农
	 *         <p>
	 *         Description
	 *         </p>
	 * @date 2017-12-30 21:22:26
	 */
	public static class ConnectionTypeConsts {

		/**
		 * MySql 连接
		 */
		public static final int MY_SQL = 1;

		/**
		 * Sql Server 连接
		 */
		public static final int SQL_SERVER = 10;

		/**
		 * Oracle 连接
		 */
		public static final int ORACLE = 20;

		/**
		 * PostgresSql 连接类型
		 */
		public final static int POSTGRESSQL = 31;
		/**
		 * DB2 连接类型
		 */
		public final static int DB2 = 32;
		/**
		 * MariaDB 连接类型
		 */
		public final static int MARIADB = 33;
		/**
		 * Sybase 连接类型
		 */
		public final static int SYBASE = 34;
		/**
		 * SQLite 连接类型
		 */
		public final static int SQLITE = 35;

		/**
		 * Access 连接类型
		 */
		public final static int ACCESS = 36;

		/**
		 * OceanBase 连接类型
		 */
		public final static int OCEANBASE = 37;

		/**
		 * redis 连接
		 */
		public static final int REDIS = 101;

		/**
		 * rabbitmq 连接
		 */
		public static final int RABBIT_MQ = 201;

		/**
		 * mongodb 连接
		 */
		public static final int MONGO_DB = 301;

		private final static Map<Integer, ConnectionTypeInfo> NAME_MAP = new TreeMap<>();

		static {
			addConnectionTypeInfo(new ConnectionTypeInfo(MY_SQL, "MySql"));
			addConnectionTypeInfo(new ConnectionTypeInfo(SQL_SERVER, "SqlServer"));
			addConnectionTypeInfo(new ConnectionTypeInfo(ORACLE, "Oracle"));
			addConnectionTypeInfo(new ConnectionTypeInfo(POSTGRESSQL, "PostgresSql"));
			addConnectionTypeInfo(new ConnectionTypeInfo(DB2, "DB2"));
			addConnectionTypeInfo(new ConnectionTypeInfo(MARIADB, "MariaDB"));
			addConnectionTypeInfo(new ConnectionTypeInfo(SYBASE, "Sybase"));
			addConnectionTypeInfo(new ConnectionTypeInfo(SQLITE, "SQLite"));
			addConnectionTypeInfo(new ConnectionTypeInfo(ACCESS, "MS Access"));
			addConnectionTypeInfo(new ConnectionTypeInfo(OCEANBASE, "OceanBase"));

			addConnectionTypeInfo(new ConnectionTypeInfo(REDIS, "Redis"));
			addConnectionTypeInfo(new ConnectionTypeInfo(RABBIT_MQ, "Rabbitmq"));
			addConnectionTypeInfo(new ConnectionTypeInfo(MONGO_DB, "Mongodb"));
		}

		private static void addConnectionTypeInfo(ConnectionTypeInfo info) {
			NAME_MAP.put(info.getId(), info);
		}

		/**
		 * 获取名称
		 * 
		 * @param value
		 *            值
		 * @return
		 */
		public static String getName(Integer value) {
			if (value == null) {
				return null;
			}
			ConnectionTypeInfo info = NAME_MAP.get(value);
			if (info == null) {
				return null;
			}
			return info.getName();
		}

		/**
		 * 获取连接信息集合
		 * 
		 * @return
		 *
		 */
		public static Collection<ConnectionTypeInfo> getConnectionTypeInfos() {
			return NAME_MAP.values();
		}
	}

}
